﻿using System;
using System.Linq;
using System.Web;
using CodeCamp.BL.Model;

namespace CodeCamp.BL
{
	public partial class CodeCampBL
	{
		#region Private Methods

		private static byte[] getBytes(HttpPostedFileBase photo)
		{
			var data = new byte[photo.ContentLength];
			photo.InputStream.Read(data, 0, data.Length);
			return data;
		}

		public static Attachment GetAttachment(Guid id)
		{
			using (var context = new CodeCampEntities())
			{
				Attachment result = context.Attachments.FirstOrDefault(a => a.AttachmentID == id);
				return result;
			}
		}


		private static Camp getCamp(CodeCampEntities context)
		{
			Camp camp = context.Camps
				.Include("Sessions.Speakers")
				.FirstOrDefault(c => c.IsActive);

			if (camp == null)
			{
				throw new InvalidOperationException("No available open camp");
			}
			return camp;
		}

		/// <summary>
		/// Gets the bare member profile without anciliery relationships.
		/// </summary>
		/// <param name="context">The context.</param>
		/// <param name="userID">The user ID.</param>
		/// <returns></returns>
		private static MemberProfile getMemberProfile(CodeCampEntities context, Guid userID)
		{
			MemberProfile result = context.MemberProfiles.FirstOrDefault(p => p.UserId == userID);
			return result;
		}

		#endregion
	}
}